package com.vitabuybuy.tv.ui.shopcenter.store.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemShopClassification1Binding
import com.vitabuybuy.tv.dto.ClassificationDto
import com.library.common.base.BindRecycAdapter
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter

class ShopClassificationListAdapter :
    BindRecycAdapter<ItemShopClassification1Binding, ClassificationDto>() {

    override fun onBindViewHolder(
        mBinding: ItemShopClassification1Binding,
        itemData: ClassificationDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.tvName.text = itemData.name

        mBinding.tagLayout.adapter = object : TagAdapter<ClassificationDto.ChildrenBean>(itemData.children) {
            override fun getView(parent: FlowLayout, position: Int, str: ClassificationDto.ChildrenBean): View {
                val tvTip = LayoutInflater.from(mContext).inflate(
                    R.layout.item_shop_classification_2,
                    mBinding.tagLayout, false
                ) as TextView
                tvTip.text = str.name
                val ll = tvTip.layoutParams as ViewGroup.MarginLayoutParams
                ll.rightMargin = 50
                ll.bottomMargin = 40
                tvTip.layoutParams = ll
                return tvTip
            }
        }
        mBinding.tagLayout.setOnTagClickListener { _, position, _ ->
            onTagClick.invoke(itemData.children[position])
            true
        }
    }

    lateinit var onTagClick:(bean:ClassificationDto.ChildrenBean) ->Unit

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_shop_classification_1
    }

}
